package cn.bandeqing.customer.controller;

import cn.bandeqing.base.resp.Resp;
import cn.bandeqing.base.resp.Table;
import cn.bandeqing.customer.req.CustomerAddressTableReq;
import cn.bandeqing.customer.req.CustomerSaveOrUpdateReq;
import cn.bandeqing.customer.req.CustomerTableReq;
import cn.bandeqing.customer.resp.CustomerAddressTable;
import cn.bandeqing.customer.resp.CustomerTable;
import cn.bandeqing.customer.rpc.ICustomerRpc;
import cn.bandeqing.wechatminiapp.req.CustomerAddressSaveOrUpdateReq;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/customer")
@RestController
@Tag(name = "客户")
public class CustomerController {

    @DubboReference
    private ICustomerRpc customerRpc;

    @Operation(summary = "table")
    @PostMapping("/address/table")
    public Resp<Table<CustomerAddressTable>> addressTable(@RequestBody @Valid CustomerAddressTableReq req) {
        return customerRpc.addressTable(req);
    }

    @Operation(summary = "创建或更新")
    @PostMapping("/address/saveOrUpdate")
    public Resp<Void> addressSaveOrUpdate(@RequestBody @Valid CustomerAddressSaveOrUpdateReq req) {
        customerRpc.addressSaveOrUpdate(req);
        return Resp.success();
    }

    @Operation(summary = "table")
    @PostMapping("/table")
    public Resp<Table<CustomerTable>> table(@RequestBody @Valid CustomerTableReq req) {
        return customerRpc.table(req);
    }

    @Operation(summary = "创建或更新")
    @PostMapping("/saveOrUpdate")
    public Resp<Void> saveOrUpdate(@RequestBody @Valid CustomerSaveOrUpdateReq req) {
        customerRpc.saveOrUpdate(req);
        return Resp.success();
    }

}
